package com.ufaud.ais.test;

import java.util.Iterator;

import org.hibernate.Criteria;
import org.hibernate.FetchMode;
import org.hibernate.Hibernate;
import org.hibernate.classic.Session;
import org.hibernate.criterion.Expression;
import org.junit.Test;

import util.HibernateUtil;

import com.ufaud.ais.sys.entity.Department;

public class TT {

	@Test
	public void testtt(){
		Session session = HibernateUtil.currentSession();
		System.out.println("------ testTT ------");
        Criteria criteria = session.createCriteria(Department.class);
        criteria.add(Expression.eq("deptId",new Long(1)));
        Department dept =  (Department)criteria.setFetchMode("subDeptSet", FetchMode.JOIN).list().get(0);
        HibernateUtil.closeSession();
        System.out.println(dept.getDeptName());
		System.out.println(dept.getSubDeptSet());
		
		
		for(Iterator<Department> iter = dept.getSubDeptSet().iterator(); iter.hasNext();) {
			System.out.println(iter.next().getSubDeptSet());
		}
	}
	
	@Test
	public void testttt(){
		Session session = HibernateUtil.currentSession();
		System.out.println("------ testTTtt ------");
        Criteria criteria = session.createCriteria(Department.class);
        criteria.add(Expression.eq("deptId",new Long(1)));
        Department dept =  (Department)criteria.list().get(0);
		//Hibernate.initialize(dept.getSubDeptSet());
        HibernateUtil.closeSession();
        System.out.println(dept.getDeptName());
		System.out.println(dept.getSubDeptSet());
		
		
		for(Iterator<Department> iter = dept.getSubDeptSet().iterator(); iter.hasNext();) {
			System.out.println(iter.next().getSubDeptSet());
		}
	}
}
